﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using WPF_Dialogs.Custom_Controls;

namespace WPF_Dialogs.Dialogs
{
    /// <summary>
    /// Interaktionslogik für PromptDialog.xaml
    /// </summary>
    public partial class PromptDialog : Window, IDialog
    {
        /// <summary>
        /// Gets or sets the dialog result value, which is the value that is returned from the <see cref="M:System.Windows.Window.ShowDialog"/> method.
        /// </summary>
        /// <value></value>
        /// <returns>A <see cref="T:System.Nullable`1"/> value of type <see cref="T:System.Boolean"/>. The default is false.</returns>
        /// <exception cref="T:System.InvalidOperationException">
        /// 	<see cref="P:System.Windows.Window.DialogResult"/> is set before a window is opened by calling <see cref="M:System.Windows.Window.ShowDialog"/>, or a window opened by calling <see cref="M:System.Windows.Window.Show"/>.</exception>
        public new EDialogResult DialogResult { set; get; }

        /// <summary>
        /// Creates a new PromptDialog
        /// </summary>
        /// <param name="text">The Text which is choosen (a question maybe)</param>
        /// <param name="title">An optional Title for your PromptDilaog, if its not given, the text will be Displayed in title</param>
        public PromptDialog(string text, string title = "")
        {
            InitializeComponent();
            this.textBoxInput.Focus();
            if (title == "")
                this.Title = text;
            else
                this.Title = title;
            this.labelText.Content = text;
        }

        #region public functions
        public EDialogResult showDialog()
        {
            this.textBoxInput.SelectAll();
            this.ShowDialog();
            return this.DialogResult;
        }
        #endregion

        #region public properties
        /// <summary>
        /// Returns the Input
        /// </summary>
        public string Input { get; private set; }

        /// <summary>
        /// Sets the content of the label text.
        /// </summary>
        /// <value>The content of the label text.</value>
        public object LabelTextContent
        {
            set
            {
                this.labelText.Content = value;
            }
        }

        /// <summary>
        /// Sets the content of the button OK.
        /// </summary>
        /// <value>The content of the button OK.</value>
        public object ButtonOKContent
        {
            set
            {
                this.buttonOK.Content = value;
            }
        }

        /// <summary>
        /// Sets the content of the button cancel.
        /// </summary>
        /// <value>The content of the button cancel.</value>
        public object ButtonCancelContent
        {
            set
            {
                this.buttonCancel.Content = value;
            }
        }

        /// <summary>
        /// Sets the title of the PromptDialog
        /// </summary>
        public string TitleText
        {
            set
            {
                this.Title = value;
            }
        }
        #endregion

        #region private functions
        private void DialogButton_clicked(object sender, RoutedEventArgs e)
        {
            DialogButton db = e.OriginalSource as DialogButton;
            this.DialogResult = db.DialogResult;
            if (this.DialogResult == EDialogResult.OK)
                Input = this.textBoxInput.Text;
            this.Close();
            e.Handled = true;
        }

        private new bool? ShowDialog()
        {
            return base.ShowDialog();
        }

        private void textBoxFolderName_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter || e.Key == Key.Return)
            {
                this.DialogResult = EDialogResult.OK;
                Input = this.textBoxInput.Text;
                this.Close();
            }
            e.Handled = true;
        }
        #endregion
    }
}
